home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Frameworks / Argus Starter 2.0 / Windows / SampleWindow.cp next >
Encoding:
Text File  |  1995-06-25  |  5.2 KB  |  199 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  
  3.     SampleWindow.cp
  4.  
  5. ***********************************************************************/
  6.  
  7. /*
  8.     A simple window for the Starter application.
  9. */
  10.  
  11. #include "Fn_Prototypes.h"
  12. #include "SampleDialog.h"
  13. #include "SampleList.h"
  14.  
  15. #define DRAG_THRESHOLD 30
  16. #define DIALOG_BUTTON  400
  17. #define LIST_BUTTON    401
  18. #define AE_BUTTON      402
  19. #define ERR_BUTTON     403
  20. #define TBD_BUTTON     404
  21.  
  22. extern int gNewWindowLeft;
  23. extern int gNewWindowTop;
  24.  
  25. /********** Prototypes */
  26. void MyCreateWindow(       short       winID,
  27.                            Ptr         winRec,
  28.                            WindowPtr   behind,
  29.                            int         top,
  30.                            int         left,
  31.                            int         offset,
  32.                            int         errID );
  33. void MyDoContent(          WindowPtr   w,
  34.                            EventRecord *e );
  35. void MyDoUpdateWindow(     WindowPtr   w );
  36. void MyDoActivateWindow(   WindowPtr   w );
  37. void MyDoDeactivateWindow( WindowPtr   w );
  38.  
  39.  
  40. /********** CreateWindow */
  41.  
  42. void MyCreateWindow( short     winID,
  43.                      Ptr       winRec,
  44.                      WindowPtr behind,
  45.                      int       top,
  46.                      int       left,
  47.                      int       offset,
  48.                      int       errID )
  49. {
  50.     WindowPtr     w;
  51.     ControlHandle c;
  52.     
  53.     if ( ( w = GetNewWindow( winID, winRec, behind ) ) == nil )
  54.         FnErr_DisplayStrID( errID, TRUE );
  55.     if (((screenBits.bounds.right - gNewWindowLeft) < DRAG_THRESHOLD) ||
  56.         ((screenBits.bounds.bottom - gNewWindowTop) < DRAG_THRESHOLD))
  57.     {
  58.         gNewWindowLeft = left;
  59.         gNewWindowTop = top;
  60.     }
  61.     
  62.     MoveWindow( w, gNewWindowLeft, gNewWindowTop, FALSE );
  63.     gNewWindowLeft += offset;
  64.     gNewWindowTop += offset;
  65.     
  66.     c = GetNewControl( DIALOG_BUTTON, w );
  67.     (**c).contrlRfCon = DIALOG_BUTTON;
  68.     c = GetNewControl( LIST_BUTTON, w );
  69.     (**c).contrlRfCon = LIST_BUTTON;
  70.     c = GetNewControl( AE_BUTTON, w );
  71.     (**c).contrlRfCon = AE_BUTTON;
  72.     c = GetNewControl( ERR_BUTTON, w );
  73.     (**c).contrlRfCon = ERR_BUTTON;
  74.     c = GetNewControl( TBD_BUTTON, w );
  75.     (**c).contrlRfCon = TBD_BUTTON;
  76.     
  77.     ShowWindow( w );
  78.     DrawControls( w );
  79. }
  80.  
  81.  
  82. /********** DoContent */
  83.  
  84. void MyDoContent( WindowPtr w, EventRecord *e )
  85. {
  86.     ControlHandle c;
  87.     GrafPtr       savePort;
  88.     Point         theLocation;
  89.     short         theClick;
  90.     int           theResponse;
  91.  
  92.     StandardFileReply  mySFR;
  93.     SFTypeList         myTypeList;
  94.     // OSErr              myErr;
  95.     // Str255             myApp = "\pEditor";
  96.     // FSSpec             mySpec;
  97.  
  98.     savePort = thePort;
  99.     SetPort( w );
  100.     theLocation = (*e).where;
  101.     GlobalToLocal( &theLocation );
  102.     theClick = FindControl( theLocation, w, &c );
  103.     if( theClick == inButton )
  104.     {
  105.         theResponse = TrackControl( c, theLocation, nil );
  106.         if( theResponse != 0 )
  107.         {
  108.             switch( (**c).contrlRfCon )
  109.             {
  110.                  case DIALOG_BUTTON:
  111.                      MySampleDialog();
  112.                      break;
  113.                  case LIST_BUTTON:
  114.                      MyListDialog();
  115.                      break;
  116.                  case AE_BUTTON:
  117.                      myTypeList[0] = 'TEXT';
  118.                      myTypeList[1] = 'APPL';
  119.                      StandardGetFile(nil,2,myTypeList,&mySFR);
  120.                      if( mySFR.sfGood )
  121.                         FnAE_SendOpenAE(&(mySFR.sfFile));
  122.                      // myErr = FSMakeFSSpec(0,0,myApp,&mySpec);
  123.                      // if( myErr == noErr )
  124.                      //     FnAE_SendOpenAE(&mySpec);
  125.                      break;
  126.                  case ERR_BUTTON:
  127.                      FnErr_DisplayStr(
  128.                          "\pThis is a test ",
  129.                          "\pto see if this error ",
  130.                          "\pmessage is displayed...",
  131.                          "\p",
  132.                          FALSE );
  133.                      break;
  134.                  case TBD_BUTTON:
  135.                      break;
  136.                  default:
  137.                      break;                        
  138.             }
  139.         }
  140.     }
  141.     SetPort( savePort );
  142. }
  143.  
  144.  
  145. /********** MyDoUpdateWindow */
  146.  
  147. void MyDoUpdateWindow( WindowPtr w )
  148. {
  149.     GrafPtr savePort;
  150.     
  151.     GetPort( &savePort );
  152.     SetPort( w );
  153.     BeginUpdate( w );
  154.         DrawControls( w );
  155.     EndUpdate( w );
  156.     SetPort( savePort );
  157. }
  158.  
  159.  
  160. /********** MyDoActivateWindow */
  161.  
  162. void MyDoActivateWindow( WindowPtr w )
  163. {
  164.     GrafPtr       savePort;
  165.     ControlHandle cntl;
  166.     
  167.     GetPort( &savePort );
  168.     SetPort( w );
  169.         cntl = ((WindowPeek)(w))->controlList;
  170.         while( cntl != 0 )
  171.         {
  172.             HiliteControl( cntl, 0 );
  173.             cntl = (*cntl)->nextControl;
  174.         }
  175.         DrawControls( w );
  176.     SetPort( savePort );
  177. }
  178.  
  179.  
  180. /********** MyDoDeactivateWindow */
  181.  
  182. void MyDoDeactivateWindow( WindowPtr w )
  183. {
  184.     GrafPtr       savePort;
  185.     ControlHandle cntl;
  186.     
  187.     GetPort( &savePort );
  188.     SetPort( w );
  189.         cntl = ((WindowPeek)(w))->controlList;
  190.         while( cntl != 0 )
  191.         {
  192.             HiliteControl( cntl, 255 );
  193.             cntl = (*cntl)->nextControl;
  194.         }
  195.         DrawControls( w );
  196.     SetPort( savePort );
  197. }
  198.  
  199. // End of File